package cn.iocoder.yudao.module.biz.service.specialWorkType;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.specialWorkType.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.specialWorkType.BizSpecialWorkTypeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.biz.convert.specialWorkType.BizSpecialWorkTypeConvert;
import cn.iocoder.yudao.module.biz.dal.mysql.specialWorkType.BizSpecialWorkTypeMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 工种类型 Service 实现类
 *
 * @author guangpu
 */
@Service
@Validated
public class BizSpecialWorkTypeServiceImpl implements BizSpecialWorkTypeService {

    @Resource
    private BizSpecialWorkTypeMapper specialWorkTypeMapper;

    @Override
    public String createSpecialWorkType(BizSpecialWorkTypeCreateReqVO createReqVO) {
        // 插入
        BizSpecialWorkTypeDO specialWorkType = BizSpecialWorkTypeConvert.INSTANCE.convert(createReqVO);
        specialWorkTypeMapper.insert(specialWorkType);
        // 返回
        return specialWorkType.getId();
    }

    @Override
    public void updateSpecialWorkType(BizSpecialWorkTypeUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateSpecialWorkTypeExists(updateReqVO.getId());
        // 更新
        BizSpecialWorkTypeDO updateObj = BizSpecialWorkTypeConvert.INSTANCE.convert(updateReqVO);
        specialWorkTypeMapper.updateById(updateObj);
    }

    @Override
    public void deleteSpecialWorkType(String id) {
        // 校验存在
        this.validateSpecialWorkTypeExists(id);
        // 删除
        specialWorkTypeMapper.deleteById(id);
    }

    private void validateSpecialWorkTypeExists(String id) {
        if (specialWorkTypeMapper.selectById(id) == null) {
            throw exception(SPECIAL_WORK_TYPE_NOT_EXISTS);
        }
    }

    @Override
    public BizSpecialWorkTypeDO getSpecialWorkType(String id) {
        return specialWorkTypeMapper.selectById(id);
    }

    @Override
    public List<BizSpecialWorkTypeDO> getSpecialWorkTypeList(Collection<String> ids) {
        return specialWorkTypeMapper.selectBatchIds(ids);
    }

    @Override
    public List<BizSpecialWorkTypeDO> getSpecialWorkTypeListAll() {
        return specialWorkTypeMapper.selectList();
    }

    @Override
    public PageResult<BizSpecialWorkTypeDO> getSpecialWorkTypePage(BizSpecialWorkTypePageReqVO pageReqVO) {
        return specialWorkTypeMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizSpecialWorkTypeDO> getSpecialWorkTypeList(BizSpecialWorkTypeExportReqVO exportReqVO) {
        return specialWorkTypeMapper.selectList(exportReqVO);
    }

}
